package com.bawei.property.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.bawei.property.databinding.ItemColorLayoutBinding
import com.bawei.property.entity.ColorValue
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Author: Jason Zhang
 * Date: 2024/12/23
 * Desc: 颜色列表适配器
 */
class ColorListAdapter constructor(private val layoutId: Int) : BaseQuickAdapter<ColorValue, ColorListAdapter.ItemVieHolder>(layoutId){

    inner  class ItemVieHolder(val dataBinding: ItemColorLayoutBinding): BaseViewHolder(dataBinding.root)

    override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): ItemVieHolder {
        var itemBinding = DataBindingUtil.inflate<ItemColorLayoutBinding>(LayoutInflater.from(parent.context), layoutId, parent, false)
        return ItemVieHolder(itemBinding)
    }

    override fun convert(holder: ItemVieHolder, item: ColorValue) {
        holder.dataBinding.entity = item
        holder.dataBinding.executePendingBindings() //执行绑定
    }
}